|
|
|
| If strLast <> "" Then vntBookmark = datEmployees.Recordset.Bookmark
datEmployees.Recordset.Find _
"szLast_nm LIKE '" & strLast & "*'"
If datEmployees.Recordset.EOF Then
datEmployees.Recordset.Bookmark = vntBookmark
MsgBox "Employee Not Found"
End If End If
End Sub |  | After adding the Find command button you need to write some substantial code to find a record in the Recordset. See the discussion below for an explanation. |
|
|
|
|
|
|
In the Find routine, you need to declare two variables. One to hold the last name the user types into the InputBox() function; the second to hold a bookmark from the Recordset object. After asking the user to type in a last name in the input box, you need to grab the current bookmark of the Recordset object. This bookmark can be used in case the name the user types in does not exist. Youll use this bookmark to go back to the current record. |
|
|
|
|
|
|
|
|
Next, you use the Find method of the Recordset object to search where the szLast_nm field in the table is like the name typed in by the user. Add an asterisk after the last name to perform a wildcard search. If the last name is found, the recordset will be positioned to that new record. If it is not found, the recordset will be positioned at the end of the file. If the recordset is at the end of the file, you should set the Bookmark property of the Recordset object to the value you saved prior to the Find method. This will move the recordset back to the record where the user was positioned prior to searching. You should then pop up a message box to inform the user that the name was not found. |
|
|
|
|
|
|
|
|
One thing that will make the searching for last names of employees easier is to sort the data in the list box. Add an ORDER BY clause to the Command Text (SQL) property in the data control property pages. The SELECT statement should look like the following in the Command Text property: |
|
|
|
 |
|
|
|
|
SELECT * FROM tblEmployees ORDER BY szLast_nm |
|
|
|
|
|
|
|
|
One last thing is to add the Find command button to the ToggleButtons routine so that its disabled when the user enters an edit or add new mode. |
|
|
|
|
|